*********************************************************************************
*** Figure 5
*********************************************************************************

* Project: 	International threats and European defense
* Authors: 	Matthias Mader
* Date:		March 2023	

* Data: VW Project, Pane-European survey (W1)

*********************************************************************************

*** Setup

	clear
	set more off            						// Disable partitioned output
	set dp period									// Use comma instead of dot for decimals
	set linesize 80         						// Line size limit to make output more readable
	macro drop _all         						// clear all macros
	set scheme plotplainblind, permanent				// set graph scheme, e.g., cleanplots, plottig, plotplainblind, burd3, s1mono
	graph set window fontface "Times New Roman"		// set font in graphs | "Arial" | "Times New Roman"


*** Figure A2.1: Distribution of attitudes towards European defence integration
	use DATA_clean.dta, clear

	fre csdp_wouldlike
	recode csdp_wouldlike (0 = 1) (.2 .4 .6 .8 1 = 0) , gen(csdp_wouldlike1)
	tab csdp_wouldlike1 csdp_wouldlike, mis
	recode csdp_wouldlike (.2 = 1) (0 .4 .6 .8 1 = 0) , gen(csdp_wouldlike2)
	recode csdp_wouldlike (.4 = 1) (0 .2 .6 .8 1 = 0) , gen(csdp_wouldlike3)
	recode csdp_wouldlike (.6 = 1) (0 .2 .4 .8 1 = 0) , gen(csdp_wouldlike4)
	recode csdp_wouldlike (.8 = 1) (0 .2 .4 .6 1 = 0) , gen(csdp_wouldlike5)
	recode csdp_wouldlike (1 = 1) (0 .2 .4 .6 .8 = 0) , gen(csdp_wouldlike6)

	#delimit ;
	graph hbar csdp_wouldlike1 csdp_wouldlike2 csdp_wouldlike3 csdp_wouldlike4 csdp_wouldlike5 csdp_wouldlike6 ,				// Basis Graph
	over(QCOUNTRY, label(labsize(vsmall))) stack percent				// Stack, Prozente, über countryyear -> Textgröße der Labels
		bar(1, color(gs14))												// Farben ändern
		bar(2, color(gs12))
		bar(3, color(gs10))
		bar(4, color(gs6))
		bar(5, color(gs4))
		bar(6, color(gs2))
	scheme(plotplainblind)														// Hintergrund weiߍ
	legend(	off)
	blabel(bar, format(%9.0f) position(center) color(gs0) size(vsmall))	// Prozentangaben in Balken einblenden
	ysize(5)
	xsize(7)
	ylabel(0(20)100, nogrid labs(vsmall))										
	ytitle("", size(zero))
	title("", size(medsmall))											// Titel
	plotregion( margin(0 5 0 0) lstyle(none)) 
	graphregion(margin(0 0 0 0) color(white) lwidth(huge) lstyle(none))	
	name(IDtypes, replace)													// Name geben
	;
	#delimit cr


*** Figure A2.2: Distribution of threat perception: Terrorist attacks
	use DATA_clean.dta, clear

	fre Q8_1
	recode Q8_1 (1 = 1) (2 3 4 5 6 7 = 0) , gen(threat1)
	tab Q8_1 threat1, mis
	recode Q8_1 (2 = 1) (1 3 4 5 6 7 = 0) , gen(threat2)
	recode Q8_1 (3 = 1) (1 2 4 5 6 7 = 0) , gen(threat3)
	recode Q8_1 (4 = 1) (1 2 3 5 6 7 = 0) , gen(threat4)
	recode Q8_1 (5 = 1) (1 2 3 4 6 7 = 0) , gen(threat5)
	recode Q8_1 (6 = 1) (1 2 3 4 5 7 = 0) , gen(threat6)
	recode Q8_1 (7 = 1) (1 2 3 4 5 6 = 0) , gen(threat7)

	#delimit ;
	graph hbar threat1 threat2 threat3 threat4 threat5 threat6 threat7 ,				// Basis Graph
	over(QCOUNTRY, label(labsize(vsmall))) stack percent				// Stack, Prozente, über countryyear -> Textgröße der Labels
		bar(1, color(gs14))												// Farben ändern
		bar(2, color(gs12))
		bar(3, color(gs10))
		bar(4, color(gs8))
		bar(5, color(gs6))
		bar(6, color(gs4))
		bar(7, color(gs2))
	scheme(plotplainblind)														// Hintergrund weiߍ
	legend(	off)
	blabel(bar, format(%9.0f) position(center) color(gs0) size(vsmall))	// Prozentangaben in Balken einblenden
	ysize(5)
	xsize(7)
	ylabel(0(20)100, nogrid labs(vsmall))										
	ytitle("", size(zero))
	title("", size(medsmall))											// Titel
	plotregion( margin(0 5 0 0) lstyle(none)) 
	graphregion(margin(0 0 0 0) color(white) lwidth(huge) lstyle(none))	
	name(Terroristattacks, replace)													// Name geben
	;
	#delimit cr


*** Figure A2.3: Distribution of threat perception: Cyber-attacks on [COUNTRY]
	use DATA_clean.dta, clear

	fre Q8_2
	recode Q8_2 (1 = 1) (2 3 4 5 6 7 = 0) , gen(threat1)
	tab Q8_2 threat1, mis
	recode Q8_2 (2 = 1) (1 3 4 5 6 7 = 0) , gen(threat2)
	recode Q8_2 (3 = 1) (1 2 4 5 6 7 = 0) , gen(threat3)
	recode Q8_2 (4 = 1) (1 2 3 5 6 7 = 0) , gen(threat4)
	recode Q8_2 (5 = 1) (1 2 3 4 6 7 = 0) , gen(threat5)
	recode Q8_2 (6 = 1) (1 2 3 4 5 7 = 0) , gen(threat6)
	recode Q8_2 (7 = 1) (1 2 3 4 5 6 = 0) , gen(threat7)

	#delimit ;
	graph hbar threat1 threat2 threat3 threat4 threat5 threat6 threat7 ,				// Basis Graph
	over(QCOUNTRY, label(labsize(vsmall))) stack percent				// Stack, Prozente, über countryyear -> Textgröße der Labels
		bar(1, color(gs14))												// Farben ändern
		bar(2, color(gs12))
		bar(3, color(gs10))
		bar(4, color(gs8))
		bar(5, color(gs6))
		bar(6, color(gs4))
		bar(7, color(gs2))
	scheme(plotplainblind)														// Hintergrund weiߍ
	legend(	off)
	blabel(bar, format(%9.0f) position(center) color(gs0) size(vsmall))	// Prozentangaben in Balken einblenden
	ysize(5)
	xsize(7)
	ylabel(0(20)100, nogrid labs(vsmall))										
	ytitle("", size(zero))
	title("", size(medsmall))											// Titel
	plotregion( margin(0 5 0 0) lstyle(none)) 
	graphregion(margin(0 0 0 0) color(white) lwidth(huge) lstyle(none))	
	name(Cyberattacks, replace)													// Name geben
	;
	#delimit cr


*** Figure A2.4: Distribution of threat perceptions: Hostile states influencing [country]’s elections 
	use DATA_clean.dta, clear

	fre Q8_3
	recode Q8_3 (1 = 1) (2 3 4 5 6 7 = 0) , gen(threat1)
	tab Q8_3 threat1, mis
	recode Q8_3 (2 = 1) (1 3 4 5 6 7 = 0) , gen(threat2)
	recode Q8_3 (3 = 1) (1 2 4 5 6 7 = 0) , gen(threat3)
	recode Q8_3 (4 = 1) (1 2 3 5 6 7 = 0) , gen(threat4)
	recode Q8_3 (5 = 1) (1 2 3 4 6 7 = 0) , gen(threat5)
	recode Q8_3 (6 = 1) (1 2 3 4 5 7 = 0) , gen(threat6)
	recode Q8_3 (7 = 1) (1 2 3 4 5 6 = 0) , gen(threat7)

	#delimit ;
	graph hbar threat1 threat2 threat3 threat4 threat5 threat6 threat7 ,				// Basis Graph
	over(QCOUNTRY, label(labsize(vsmall))) stack percent				// Stack, Prozente, über countryyear -> Textgröße der Labels
		bar(1, color(gs14))												// Farben ändern
		bar(2, color(gs12))
		bar(3, color(gs10))
		bar(4, color(gs8))
		bar(5, color(gs6))
		bar(6, color(gs4))
		bar(7, color(gs2))
	scheme(plotplainblind)														// Hintergrund weiߍ
	legend(	off)
	blabel(bar, format(%9.0f) position(center) color(gs0) size(vsmall))	// Prozentangaben in Balken einblenden
	ysize(5)
	xsize(7)
	ylabel(0(20)100, nogrid labs(vsmall))										
	ytitle("", size(zero))
	title("", size(medsmall))											// Titel
	plotregion( margin(0 5 0 0) lstyle(none)) 
	graphregion(margin(0 0 0 0) color(white) lwidth(huge) lstyle(none))	
	name(Elections, replace)													// Name geben
	;
	#delimit cr


*** Figure A2.5: Distribution of threat perceptions: Russia’s territorial ambitions 
	use DATA_clean.dta, clear

	fre Q8_5
	recode Q8_5 (1 = 1) (2 3 4 5 6 7 = 0) , gen(threat1)
	tab Q8_5 threat1, mis
	recode Q8_5 (2 = 1) (1 3 4 5 6 7 = 0) , gen(threat2)
	recode Q8_5 (3 = 1) (1 2 4 5 6 7 = 0) , gen(threat3)
	recode Q8_5 (4 = 1) (1 2 3 5 6 7 = 0) , gen(threat4)
	recode Q8_5 (5 = 1) (1 2 3 4 6 7 = 0) , gen(threat5)
	recode Q8_5 (6 = 1) (1 2 3 4 5 7 = 0) , gen(threat6)
	recode Q8_5 (7 = 1) (1 2 3 4 5 6 = 0) , gen(threat7)

	#delimit ;
	graph hbar threat1 threat2 threat3 threat4 threat5 threat6 threat7 ,				// Basis Graph
	over(QCOUNTRY, label(labsize(vsmall))) stack percent				// Stack, Prozente, über countryyear -> Textgröße der Labels
		bar(1, color(gs14))												// Farben ändern
		bar(2, color(gs12))
		bar(3, color(gs10))
		bar(4, color(gs8))
		bar(5, color(gs6))
		bar(6, color(gs4))
		bar(7, color(gs2))
	scheme(plotplainblind)														// Hintergrund weiߍ
	legend(	off)
	blabel(bar, format(%9.0f) position(center) color(gs0) size(vsmall))	// Prozentangaben in Balken einblenden
	ysize(5)
	xsize(7)
	ylabel(0(20)100, nogrid labs(vsmall))										
	ytitle("", size(zero))
	title("", size(medsmall))											// Titel
	plotregion( margin(0 5 0 0) lstyle(none)) 
	graphregion(margin(0 0 0 0) color(white) lwidth(huge) lstyle(none))	
	name(Russia, replace)													// Name geben
	;
	#delimit cr


*** Figure A2.6: Distribution of threat perceptions: The development of China as a world power
	use DATA_clean.dta, clear

	fre Q8_6
	recode Q8_6 (1 = 1) (2 3 4 5 6 7 = 0) , gen(threat1)
	tab Q8_6 threat1, mis
	recode Q8_6 (2 = 1) (1 3 4 5 6 7 = 0) , gen(threat2)
	recode Q8_6 (3 = 1) (1 2 4 5 6 7 = 0) , gen(threat3)
	recode Q8_6 (4 = 1) (1 2 3 5 6 7 = 0) , gen(threat4)
	recode Q8_6 (5 = 1) (1 2 3 4 6 7 = 0) , gen(threat5)
	recode Q8_6 (6 = 1) (1 2 3 4 5 7 = 0) , gen(threat6)
	recode Q8_6 (7 = 1) (1 2 3 4 5 6 = 0) , gen(threat7)

	#delimit ;
	graph hbar threat1 threat2 threat3 threat4 threat5 threat6 threat7 ,				// Basis Graph
	over(QCOUNTRY, label(labsize(vsmall))) stack percent				// Stack, Prozente, über countryyear -> Textgröße der Labels
		bar(1, color(gs14))												// Farben ändern
		bar(2, color(gs12))
		bar(3, color(gs10))
		bar(4, color(gs8))
		bar(5, color(gs6))
		bar(6, color(gs4))
		bar(7, color(gs2))
	scheme(plotplainblind)														// Hintergrund weiߍ
	legend(	off)
	blabel(bar, format(%9.0f) position(center) color(gs0) size(vsmall))	// Prozentangaben in Balken einblenden
	ysize(5)
	xsize(7)
	ylabel(0(20)100, nogrid labs(vsmall))										
	ytitle("", size(zero))
	title("", size(medsmall))											// Titel
	plotregion( margin(0 5 0 0) lstyle(none)) 
	graphregion(margin(0 0 0 0) color(white) lwidth(huge) lstyle(none))	
	name(China, replace)													// Name geben
	;
	#delimit cr


*** Figure A2.7: Distribution of identity types
	use DATA_clean.dta, clear

	fre idconfig
	recode idconfig (1 = 1) (2 3 4 = 0) , gen(idtype1)
	recode idconfig (2 = 1) (1 3 4 = 0) , gen(idtype2)
	recode idconfig (3 = 1) (1 2 4 = 0) , gen(idtype3)
	recode idconfig (4 = 1) (1 2 3 = 0) , gen(idtype4)


	#delimit ;
	graph hbar idtype1 idtype2 idtype3 idtype4 ,				// Basis Graph
	over(QCOUNTRY, label(labsize(vsmall))) stack percent				// Stack, Prozente, über countryyear -> Textgröße der Labels
		bar(1, color(gs14))												// Farben ändern
		bar(2, color(gs10))
		bar(3, color(gs6))
		bar(4, color(gs2))
	scheme(plotplainblind)														// Hintergrund weiߍ
	legend(	off)
	blabel(bar, format(%9.0f) position(center) color(gs0) size(vsmall))	// Prozentangaben in Balken einblenden
	ysize(5)
	xsize(7)
	ylabel(0(20)100, nogrid labs(vsmall))										
	ytitle("", size(zero))
	title("", size(medsmall))											// Titel
	plotregion( margin(0 5 0 0) lstyle(none)) 
	graphregion(margin(0 0 0 0) color(white) lwidth(huge) lstyle(none))	
	name(IDtypes, replace)													// Name geben
	;
	#delimit cr

